package com.cskaoyan.service;

import com.cskaoyan.bean.stat.GoodsStatVO;
import com.cskaoyan.bean.stat.OrderStatVO;
import com.cskaoyan.bean.stat.StatVO;
import com.cskaoyan.bean.stat.UserStatVO;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class StatServiceImpl implements StatService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    OrderMapper orderMapper;

    @Override
    public StatVO<UserStatVO> queryUserStat() {
        List<UserStatVO> userStatVOS = userMapper.selectStatOfUser();
        Collections.reverse(userStatVOS);

        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");

        StatVO statVO = new StatVO();
        statVO.setColumns(columns);
        statVO.setRows(userStatVOS);
        return statVO;
    }

    @Override
    public StatVO<OrderStatVO> queryOrderStat() {
        List<OrderStatVO> orderStatVOS = orderMapper.queryOrderStat();
        Collections.reverse(orderStatVOS);

        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");

        StatVO statVO = new StatVO();
        statVO.setColumns(columns);
        statVO.setRows(orderStatVOS);

        return statVO;
    }

    @Override
    public StatVO<GoodsStatVO> queryGoodsStat(){
        List<GoodsStatVO> goodsStatVOS = orderMapper.queryGoodsStat();
        Collections.reverse(goodsStatVOS);

        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("amount");
        columns.add("products");

        StatVO statVO = new StatVO();
        statVO.setColumns(columns);
        statVO.setRows(goodsStatVOS);

        return statVO;
    }

}
